Files:
These are programs or programs fragments which may be useful. Contributions
in C, C++, or Java are welcome.
Standard Image Format
Here is a synopsis of the standard format for an image W pixels wide
by H pixels high.
Header: 6 bytes of data. Three two-byte integers (high order byte first
- "big endian" or "Motorola" encoding):
- Bytes 1 -> 2: The number of Columns in the image (W). Valid values
are 1 - 65535
- Bytes 3 -> 4: The number of Rows in the image (H). Valid values
are 1 - 65535
- Bytes 5 -> 6: The number of colors. Valid values are 1 or 3.
The number of colors is 1 if the image is monochrome (gray scale) or
3 if the image is color. In that case there are three color planes stored
in this order: Red (first), Green, Blue (last).
- Bytes 7 -> (WxH + 6): Monochrome color data if the number of colors
is 1.
-
- Bytes 7-(WxH + 6): Red color data if the number of colors is 3
- Bytes (WxH + 6 )-> (2xWxH + 6): Green color data
- Bytes (2xWxH + 6 )-> (3xWxH + 6) Blue color data
-
The data are bytes read out in rows running from the top left. The printer's
convention is used: 0x00 is white (or maximum amount of a color) and 0xFF
is black.
Sample Images
Here are two images in standard image format and in TIFF format (converted
using program img2tif.c described below).
You will need to download the *.img
files in binary format,
but your browser might open the *.tif
files directly.
Programs to read/write standard image files.
The C program files here all include the compile string in the
comments.
This makes it very easy to compile any of these files on a Unix system
--
just type
grep cc myfile.c | csh
- img.c - Image utilities. Written as carefully
as MAG could, with possibly excessive error checking. This shows how
to write the header in a way that works on both big-endian and
small-endian computers. Note that all function calls expect the
program name as the 1st argument, so that if an error occurs, the
program responsible is identified. Especially useful when running
batch files with many programs.
- img.h - .img definitions. Shows the basic
image structure as stored in memory and the headers structure on disk.
- bmp.h - .bmp definitions. Shows the BMP image
header structure.
- add_head.c - Queries operator for
raw data file name containing image bytes and header numbers and writes
out the image in standard format.
- prt_hdr.c - Prints out the header
information for the file given on the command line. This shows
how to read the header in a way that works on both big-endian and small-endian
computers.
- img2bmp.c - Takes
input image file name from command line and converts it to a
MicroSoft BMP standard
file. The resulting file is uncompressed, so expect large files,
even for greyscale.
- img2tif.c - Takes
input image file name from command line and converts it to a standard TIFF
file. The resulting file is uncompressed (to prevent infringement of the
LZW patent). This software has been carefully compared to the TIFF v6.0
Specification although a few TIFF readers (all shareware) which do not
follow the Specification recommendations (on strip width) may experience
difficulties.
- tif2img.c - Takes TIFF
input image file name from command line and converts it to an img
file. Current implementation can only create greyscale output
image. Uses the TIFF library. See the man pages for libtiff on a
unix system for details.
- b_di2tif.c - Same as above except
it converts a batch of images. This is useful in making animations, such
as the one at the top of the course home page.
Other Software
CS/ECE 545 Staff
Contents ©1997 - 2011
Norman Wittels and Michael A. Gennert