Image File Formats
CSCI N351
Andy Harris
Indiana University / Purdue University - Indianapolis
Image Questions
Does a grayscale GIF image take up less space than a color image?
How about a black and white (2 colors only) image?
Does storing an image in JPG or PNG change the answer to this question?
Can an animated gif have more than 256 colors?
Can an animated gif have more than one transparent color?
More Image Questions
Can PNG handle animations?
Why is JPG sometimes called JFIF?
How does the variable compression of a JPG work?
Which is the best format for an image with text?
GIF Images
Graphic Interchange Format
Standard format
One of oldest formats
flexible and well-known
falling from favor
GIF Bit Depth
256 element palette of 24-bit colors
Only 256 colors in image, but each is defined in 24 bits
8 bits per pixel, which refer to color numbers
'paint by number' approach
Non-registered colors are dithered
GIFS and Transparency
One color can be stored as transparent
Replaced with background on rendering
no true alpha
GIF Animation
Multi-frame images are animated
Each frame can have an independant palette
Control blocks determine time between frames
Automated in The Gimp, Gif Construction Set
Animation can be optimized (store only changes in frames)
GIF Compression
LZW (Limpel-Ziv-Welch) Compression
Based on RLE (Run-Length Encoding)
LZW demo
Patent owned by Unisys
Unisys requires a licensing fee for any software using the LZW codec
lossless compression
GIF Strengths
solid color images
Images with irregular boundaries
Images needing transparency
animation
GIF Weaknesses
limited color depth
no true alpha
animated images can be quite large
legal questions regarding LZW
The JPEG (JPG) scheme
Joint Photographic Experts Group
Useful for photos
No transparency
Loses data
JPG Background
Not a file format at all
Compression algorithm
Used by Tiff 6.0, Mac Pict
Version usually called JPG is actually JFIF
(JPEG File InterChange Format)
placed in public domain by C-Cube Microsystems
JPG Bit Depth
24 bit true color
8 bits each Red, Green, Blue
No Alpha, No Transparency
No animation or multiple images
JPG Compression Algorithm
Lossy Compression
Variable Compression Rate
Use psychological tricks to emphasise important visual information
Drop less important info
"perceptually faithful"
JPG compression pt 1 - YCbCr
Convert to YCbCr color scheme
Y = brightness
Cb = blue chrominance
Cr = red chrominance
Human eye responds more to brightness than anything else
Chrominance values are downsampled (1 value for each 2x2 block)
Results in 50% of savings in file size
JPG compression pt 2 - DCT
Discrete Cosine Transform
Human eye is more sensitive to gradual changes in brightness than sudden ones
DCT throws out less important data
Groups image into 8x8 blocks
JPG compression pt 3 - Quantization
Quantization
divides each 8x8 block by a Q factor
This is where variable compression rate occurs
Quantization is where most visible information loss occurs
JPG compression pt 4 - Huffman Encoding
Applies another encoding scheme (Huffman run-length encoding
Provides one more level of compression
JPG Strengths
Completely free algorithm
Excellent compression
High color depth
Works well with photographic data
Variable compression to meet exact needs
Visual loss of detail can be unnoticable
JPG Weaknesses
No alpha or transparency
Some image loss inevitable
No support for animation
Does not handle sharp edges well
Text reproduces very badly
Generates recognizable artifacts
Repeated storage can degrade quality
PNG (Portable Network Graphics)
Devised as a replacement for GIF
Free and unencumbered algorithm (no LZW)
Can use 24 bit or color table to save space
Improvement over GIF design
PNG characteristics
True Alpha support
No animation support
Color Depth
TrueColor
Full 8-bit Alpha channel
32-bit color
PNG Compression Algorithm
Lossless algorithm
Works well with solid colors (like GIF)
No problems with proprietary algorithm
PNG Strengths
Good replacement for GIF
Better color scheme than GIF
Few legal problems
Best support for transparency
PNG Weaknesses
No animation (although a version called MBG is in the works)
Support is increasing but not completely universal
Cannot compress some images as well as lossy algorithms (JPG)
Native Formats
General Description
File formats native to image editors
XCF for Gimp
PSD for Photoshop
Native Format Strengths
Contain complete image data
Include layers
Include channel and path data
Easiest for revising image
No image loss
NativeFormat Weaknesses
Very large files
Not supported by browsers
Ancillary information (layers, channels, paths) not needed by user