The X Files team has
recently received a secret transmission from outer space, which they
have stored in a file. They know that this file is actually a
sequence of images. Each image has been encoded as a sequence of
positive integers terminated with a -1. The overall sequence of images
found in a file is terminated with a final -1.
You have been asked to help the X team by decoding these images and
displaying them on the crude but serviceable non-graphical computers to
which you have access.
Before dying of unknown causes, the radio telescope technician who
received the mysterious broadcast revealed the following facts:
- Each image is rectangular.
- Each image has at least one column and one row.
- The first integer in the image representation is the number of
columns.
- Subsequent integers represent the light intensity at a given
point or pixel.
- A pixel is represented by an integer between 0 and 255.
- The end of the image is marked with a -1.
- The last image of the file is marked with an additional -1.
- The pixels are listed a row at a time, from left to right within
a row and the rows are given from top to bottom. Thus the first pixel
given is the one in the upper left-hand corner of the image and the
last is for the lower right-hand corner.
Since your project is not well supported by the Agency's upper
management, you will have to make do with whatever tools you have
available. These include a VT100 terminal which has no capability to
display graphical images. You do, however, have a C compiler and,
luckily, have just then begun to learn how to use it in your
studies at UMBC. You could write a program to interpret the images and
display them crudely on the terminal using "ASCII graphics".
You can translate the pixel values into printable characters using the
following conversion chart:
value range char name
--------------------------------
0 - 31 space
32 - 63 . period
64 - 95 ' apostrophe
96 - 127 - dash
128 - 159 : colon
160 - 191 | vertical bar (pipe)
192 - 223 \ backslash
224 - 255 @ at sign
Notice that the intensity of the printed characters (amount of ink
used) increases as the integers increase. The intensity of each pixel
is the integer representing that pixel. (Hint)
In addition to printing each image, your program must also calculate
and display for each image (1) the total number of pixels in the
image, (2) the number of rows of pixels in the image, and (3) the
average intensity of the pixels.