Register FAQ Search Today's Posts Mark Forums Read
Go Back   JazzJackrabbit Community Forums » Maintenance & Feedback » JJ2+ Issue Tracker

Bug Report jjPAL(...).load(): possibly false positive detection of no GIF global color table?

froducish

JCF Member

Joined: Jan 1970

Posts: 12

froducish has disabled reputation

May 10, 2026, 04:37 PM
froducish is offline
Reply With Quote
jjPAL(...).load(): possibly false positive detection of no GIF global color table?

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;
}
Attached Images
File Type: gif globe.gif (242.0 KB, 0 views)
File Type: gif spr_tenna_freakout.gif (127.5 KB, 0 views)
File Type: gif consider.gif (499.6 KB, 0 views)
File Type: gif 1078739080889761993.gif (13.1 KB, 0 views)
Violet CLM

Administrator

Joined: Mar 2001

Posts: 11,313

Violet CLM has disabled reputation

May 10, 2026, 09:21 PM
Violet CLM is offline
Reply With Quote
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

JCF Member

Joined: Jan 1970

Posts: 12

froducish has disabled reputation

May 11, 2026, 01:34 AM
froducish is offline
Reply With Quote
Quote:
Originally Posted by Violet CLM View Post
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

Administrator

Joined: Mar 2001

Posts: 11,313

Violet CLM has disabled reputation

May 11, 2026, 07:54 AM
Violet CLM is offline
Reply With Quote
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.
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump

All times are GMT -8. The time now is 10:50 PM.