JazzJackrabbit Community Forums

JazzJackrabbit Community Forums (http://www.jazz2online.com/jcf/index.php)
-   JJ2+ Issue Tracker (http://www.jazz2online.com/jcf/forumdisplay.php?f=49)
-   -   Bug Report jjPAL(...).load(): possibly false positive detection of no GIF global color table? (http://www.jazz2online.com/jcf/showthread.php?t=20902)

froducish May 10, 2026 04:37 PM

jjPAL(...).load(): possibly false positive detection of no GIF global color table?
 
4 Attachment(s)
Save this as a mutator and test on a local server. Pay attention to chatlogger for angelscript warnings.
Code:

// Reference: https://en.wikipedia.org/wiki/GIF#Example_GIF_file
// Reference: https://giflib.sourceforge.net/whatsinagif/bits_and_bytes.html
bool hasGlobalColorTable(string filename) {
        jjSTREAM dat(filename);
        if (dat.getSize() < 13) {
                return false;
        }
       
        string magic;
        dat.get(magic, 6);
        if (magic != "GIF89a") {
                return false;
        }
        dat.discard(2); // discard logical screen width
        dat.discard(2); // discard logical screen height
        uint8 gctFlags;
        dat.pop(gctFlags);
        if (gctFlags & 0x80 != 0) { // "the highest true bit means that the GCT is present"
                return true;
        }
        return false;
}

void onLevelBegin() {
        jjConsole("Test GIFs by typing a filename in chat");
}

bool onLocalChat(string &in stringReceived, CHAT::Type) {
        bool res1 = jjPAL().load(stringReceived);
        bool res2 = hasGlobalColorTable(stringReceived);
        if (res1 != res2) {
                jjAlert("jjPAL().load(...) != hasGlobalColorTable(...)");
                jjAlert("    " + res1 + " != " + res2);
        }
        return true;
}


Violet CLM May 10, 2026 09:21 PM

Let's quote the relevant documentation here:

API: "an 8-bit globally-paletted GIF"
Chatlog: "does not define a global 256 color palette"

So JJ2+ is detecting that your GIF files have color tables, just not color tables that it's excited to work with. Specifically:
  • globe: seems fine
  • spr_tenna_freakout: the color table is 4 bits, not 8, and has only 16 colors, not 256.
  • consider: the color table is 6 bits, not 8, and has only 64 colors, not 256.
  • 1078739080889761993: although there is a global color table of the proper size, at least one individual gif frame defines its own unique color table, so the gif can't be loaded with a single consistent palette.

froducish May 11, 2026 01:34 AM

Quote:

Originally Posted by Violet CLM (Post 496141)
Let's quote the relevant documentation here:

API: "an 8-bit globally-paletted GIF"
Chatlog: "does not define a global 256 color palette"

So JJ2+ is detecting that your GIF files have color tables, just not color tables that it's excited to work with. Specifically:
  • globe: seems fine
  • spr_tenna_freakout: the color table is 4 bits, not 8, and has only 16 colors, not 256.
  • consider: the color table is 6 bits, not 8, and has only 64 colors, not 256.
  • 1078739080889761993: although there is a global color table of the proper size, at least one individual gif frame defines its own unique color table, so the gif can't be loaded with a single consistent palette.

The method seems a bit too strict on the last gif. touche on the rest though, wasn't in the right headspace I made this thread, I apologize.
If it's too niche of a use case to be worth padding other colors with jjPALCOLOR(0,0,0,0) I can just continue analyzing gifs using jjSTREAM to do what I desire.

Violet CLM May 11, 2026 07:54 AM

I would rather say that the last case makes the most sense: the expected use case of loading a palette from a GIF is to display all the frames in that GIF (after loading them using jjANIMATION::load). In the last case, you can't do that, because different frames have different palettes. So maybe there needs to be an overload (or whatever) of jjANIMATION::load that imports the GIF frames as 32-bit (well, 24-bit really) sprites instead.

For the other cases, padding would probably be possible, though I'm leaving in that "probably" because I haven't taken a close enough look at our GIF library yet to know how it handles those cases.


All times are GMT -8. The time now is 01:38 AM.

Powered by vBulletin® Copyright ©2000 - 2026, Jelsoft Enterprises Ltd.
JCF © 2001-Infinity Jazz2Online