I am trying to decode any Global Color Table (GCT) and/or Local Color Tables present in GIFs. As far as I can tell, it is not possible to do in a config entry...?
In the source code, for the GCT, the position and length are calculated in order to be skipped to the next block:
my $flags = Get8u(\$s, 4);
if ($flags & 0x80) { # does this image contain a color table?
# calculate color table size
$length = 3 * (2 << ($flags & 0x07));
$raf->Read($buff, $length) == $length or return 0; # skip color table
Write($outfile, $buff) or $err = 1 if $outfile;
}
I am unsure, but perhaps something along these lines would expose the list of RGB values?
# Check if the image has a color table
if ($flags & 0x80) {
# Calculate the number of colors in the color table
my $num_colors = 2 ** (($flags & 0x07) + 1);
# Calculate the length of the color table in bytes
my $length = 3 * $num_colors;
# Read the color table
my $buff;
$raf->Read($buff, $length) == $length or return 0;
# Process the color table to extract RGB values
my @colors;
for (my $i = 0; $i < $length; $i += 3) {
my ($r, $g, $b) = unpack('C3', substr($buff, $i, 3));
push @colors, { R => $r, G => $g, B => $b };
}
$et->FoundTag('GlobalColorTable', \@colors);
}
It looks to me like the source code doesn't mention LCTs? It has the same structure - there's a flag to say whether it exists, and then the table is a sequence of RGB triplets.
On a related side note:
GIF:BackgroundColor should be GIF:BackgroundColorIndex
GIF:TransparentColor should be GIF:TransparentColorIndex
Thees values give the position in the GCT for those colors (zero indexed list of entries).
The GIF spec is a bear to read, but this is a nice resource:
https://matthewflickinger.com/lab/whatsinagif/bits_and_bytes.asp (https://web.archive.org/web/20160304075538/http://qalle.net/gif89a.php)
and someone put the GIF 89a spec into HTML for us:
https://web.archive.org/web/20160304075538/http://qalle.net/gif89a.php (https://web.archive.org/web/20160304075538/http://qalle.net/gif89a.php)
Any guidance on this would be very much appreciated. It's over my head really.
- J
Sorry. I haven't forgotten about this post, but this is a very busy time of year for me and your request would involve a significant investment of time that I just don't have at the moment.
- Phil