I'm building a program in Mathematica that generates very simple GIFS that flip between single color squares. It is designed so that the image data is uncompressed, and does not use the LZW compression that most animated GIFs use. I've come across examples of uncompressed GIFs that are not animated, which are just single images, and I've come across very simple animated gifs that change color but they do use LZW. I haven't yet found an example of uncompressed and animated, and that's what I'm trying to do.
So far my program is successful at creating single frame gifs, as well as animated gifs with multiple frames but the animated gifs always come out the same color for each frame, or just some pixels change color, not the whole frame. I am trying to create animated gifs that flips from, for example, a Red Square to a Black Square, on loop.
Below are the block-by-block bytes of a GIF that my program created. I expected this is GIF to be a 2pixel by 2pixel square where the first frame is Red and then second frame is Black. Instead I got two frames of Red.
Header: 47,49,46,38,39,61 Logical Screen Descriptor: 02,00,02,00,f0,00,00 Global Color Table: ff,00,00,00,00,00 Application Extension Block: 21,ff,0b,4e,45,54,53,43,41,50,45,32, 2e,30,03,01,00,00,00 Graphic Extension Control: 21,f9,04,00,88,13,00,00 ImageDescriptor:2c,00,00,00,00,02,00,02,00,00 ImageData Block: 01,03,02,01,01,03,02,01,01,00, Graphic Extension Control: 21,f9,04,00,88,13,00,00 ImageDescriptor:2c,00,00,00,00,02,00,02,00,00, ImageData Block:01,03,02,01,01,03,02,01,01,00 Comment Extension: 21,fe,00,00 Trailer: 3B
If you'd like to look at these bytes in a hexeditor, here is the unbroken string of bytes: 47,49,46,38,39,61,02,00,02,00,f0,00,00,ff,00,00,00,00,00,21,ff,0b,4e,45,54,53,43,41,50,45,32,2e,30,03,01,00,00,00,21,f9,04,00,88,13,00,00,2c,00,00,00,00,02,00,02,00,00,01,03,02,01,01,03,02,01,01,00,21,f9,04,00,88,13,00,00,2c,00,00,00,00,02,00,02,00,00,01,03,02,01,01,03,02,01,01,00,21,fe,00,00,3B
My current thinking on what's the problem(s): Is there something wrong the LZW Minimum size (the first byte of the Image Data Block) or with the Clear Code (the third byte of the Image Data Block), because I've found that when I change them to a different value, it can sometimes make a single or double black pixel appear along with a 1-2 red pixels, but I can't figure out a pattern to the bug.
I also wonder if the background color being set to red is giving me a misleading understanding of the bug – are maybe no or very few pixels actually being drawn, but I can't tell because of the background color is the same as the as pixel color?
Here is the program I'm working on in Mathematica – It is partially commented, but I have not completed the comments yet:
https://www.wolframcloud.com/obj/8b483039-494b-476f-844d-a0f39d1d663b
And finally, these are the best resources I've come across that I have been basing my program off of are:
GifLib – What's in a Gif http://giflib.sourceforge.net/whatsinagif/index.html
Gif File Spec https://www.w3.org/Graphics/GIF/spec-gif89a.txt
Wikipedia https://en.wikipedia.org/wiki/GIF