xbdev - software development
Sunday June 16, 2024
Home | Contact | Support | Image File Format... Storing Graphics using Bits and Bytes.. | GIF File Format... Image Format (with Animation).. ..

GIF File Format...

Image Format (with Animation).. ..


GIF (.gif) Image File Format

About GIF File Format (.gif)

A GIF or Graphical Interchange Format is a type of highly compressed image.

Owned by Unisy, GIF uses the LZW compression algorithm that does not degrade the image quality (lossless format).

For each image GIF typically allow up to 8 bits per pixel and up to 256 colours are allowed across the image.

In contrast to a JPEG image, which can display up to 16 million colours and fairly touches the limits of the human eye. Back when the internet emerged, GIFs remained the best choice because they required low bandwidth and compatible for the graphics that consume solid areas of colour.

An animated GIF combines numerous images or frames into a single file and displays them in a sequence to generate an animated clip or a short video. The colour limitations are up to 256 for each frame and are likely to be the least suitable for reproducing other images and photographs with colour gradient.

Parsing/Reading GIF File (Bytes, Structure and Data)

For a GIF file, we look for the byte sequence 474946 or the ASCII sequence of GIF.

Test image, simple 8x8 white image with a cross drawn in red:

Only two colors, white (ffffff) and red (ff0000); represents an ideal test configuration for learning about file formats - as it's simple enough to identify the pattern (and can be read by hand using a hex dump). Once we've found the pattern, we can use more complicated patterns with other colors etc - this is just to get things rolling (i.e., you can load the file, and you've found its size (8x8) and of course the two colors and pixel values). It might seem easy, but for some file formats... with complex compression formats, it can be a real challenge!

Simple Javascript loader/hex viewer - loads in the .gif so you can view the contents:

Gif Hex Viewer (Including Source/Javascript) | cross8x8.gif

What you should be looking at is the first few bytes:

Type: GIF (47,49,46)
Version: 89a (38,39,61)
Width: 8 (08,00)
Height: 8 (08,00)
Packed: F7 (F7)
Color Index: 00 (00)
Aspect: 00 (00)

Header offset/structure

Image block structure

Breakdown of the File Structure (Bits and Bytes)

Lets run through the main bytes of the file format (bits in a few packed places).

Other Resources

The GIF Standard
Gif Format Information
Wiki Gifs
Introduction File Formats/Sig Ref to Security
Advert (Support Website)

Copyright (c) 2002-2024 xbdev.net - All rights reserved.
Designated articles, tutorials and software are the property of their respective owners.