Computer Science 101
Picture Files
Computer Representation
of Pictures
Common representation is as a bitmap.
• Two dimensional array of dots called pixels
(picture element).
• The array consists of rows and columns of
• With the RGB system, each pixel has
associated a 3-byte RGB value.
Picture from W&L Home Page
(stored as bmp file)
At 800%
At 2400%
How does the software know?
We know that all of the information stored
in a computer file is stored as bits, broken
into 8-bit bytes.
How does the software know whether this
binary data is to be interpreted as text,
picture, music, program instructions, etc.
File extensions
As you know, files are usually stored as
• Name of file
• A dot (or period)
• An extension that indicates the general
category of the file.
Some common extensions
Plain text
Microsoft word document
Microsoft Word Open XML Document
Portable Document Format File
Outlook mail message
Powerpoint presentation
Excel spreadsheet
Bitmap image file
JPEG image file
Mp3 audio file
Wave audio file
Some common extensions (cont.)
Log file
Apple QuickTime movie
MPEG video file
Executable file
Hypertext Markup Language file
Zipped file
Java source file
Python source file
Extension is not enough
Often the software needs more information than is
conveyed by the extension.
A .bmp file stores the RGB values for each pixel,
thus 24 bits in 3 bytes for each
Suppose there is RGB
information for 100 pixels. Is
the picture a 10 by 10, 25 by 4,
5 by 20 or what? Many other such questions.
File headers
Many file formats specify how some needed
information is to be stored in the beginning of the
The extension tells the type of format being
used; the file header encodes additional
information needed by the software accessing the
File has
• Header information
• File data
BMP File Header
For more on this topic see
BMP Header (from Fastgraph)
BMP Header (cont.)
• How many bytes into the file the specified information
is located. Here we have 0; so this information is at
the very beginning of the file.
• In this table the offset is given in decimal; we’ll need
to use hexadecimal. Get ready to convert.
Size: How many bytes are used for the information.
BMP Header (cont.)
• Identifies the kind of file data
• Often 2 byte information has the information in “right
to left” order.
• Here the 42 in hex is 66 in decimal. The 4D is 77 in
• 66 is ASCII for B, and 77 is ASCII for M.
• BM is confirming that the data is bitmap data.
BMP Header (cont.)
Start of image data:
• Where the RGB values are found.
• Let’s remember that the offset 10 is A in hex.
• Also remember that this information is 4 bytes long.
BMP Header (cont.)
• At offset 18 decimal or 12 hex.
• 4 bytes.
• At offset 22 decimal or 16 hex.
• 4 bytes.
BMP Header Summary
Some of the header info (offsets in hex):
• Signature at offset 0 – 2 bytes
• File size at offset 2 – 4 bytes
• Offset for start of image data at offset A – 4
• Width in pixels at offset 12 - 4 bytes
• Height in pixels at offset 16 – 4 bytes
96 pixels
So each square is
24 by 24
Colored Squares with Hex Editor
We see the 42 4D at offset 0
File Size (offset 2)
We see 366C for size.
• Actually bytes are right to left so 6C36. Converting this
to decimal gives 27702 bytes.
• We have 96 by 96 or 9216 pixels
• 3 bytes per pixel for RGB; so 27648 data bytes
• Plus the 54 bytes in the header giving 27702
Width and Height
(offset 12 and 16)
We see 60 for both the width and height. In
decimal this would be 96.
Bitmap Data Location (offset A)
We see 36 at location A. This means that the
bitmap data begins in location 36.
Bitmap Data (offset 36)
At location 36, we see values FF 00 FF.
• But the upper left square has red pixels.
• The BMP documents specify bottom row first.
• Red and Blue give the purple color.
Bitmap Data – Color Change
In the bottom row, there are 24 purple pixels,
FF 00 FF. Then we see FF 00 00 24 times.
• This would seem to indicate Red.
• Again, the BMP specifications indicate the colors will be in BGR
 Now

similar documents