You are to write
a program that reads, displays, and writes out images from image
files. The program should contain the following three distinct
procedures: one to read from an image file into an RGBA pixmap,
one to display the image stored in the RGBA pixmap in a window
sized to exactly fit the image, and one to write an image file
from an RGBA pixmap retrieved from the OpenGL display buffer. This
will give you three key building blocks for future assignments,
where you will be generating images and displaying them, saving
the result, and reading image files to be used for texture maps.
You are to use ImageMagick's Magick++ library
for the reading and writing of images, and to use OpenGL and GLUT
for displaying images.
The program's
user interface should respond to keyboard key presses as follows:
The program
should be named imgview, and should handle images
stored in any format supported by ImageMagick. The file cube.ppm
is a simple test image to try your program with. If your program
works with this image, try it on the image file teapot.jpg, then try it on
images of other sizes and formats.
The program
should be named imgview
and use an optional command line parameter to determine the
initial input file name. For example, if the command line is
imgview cube.ppm
the program will
first read and display the image file named cube.ppm,
before waiting for key presses to do any additional image reads or
writes. If the program command line is simply
As an assistance
in displaying the image, you should be aware that the OpenGL
routine glDrawPixels()
will draw an entire array of pixel values to the display in one
call. Likewise the OpenGL routine glReadPixels() will retrieve the current OpenGL
display buffer and copy it into a pixmap. Check the course notes
and the OpenGL documentation to get the details of how glDrawPixels() and glReadPixels are used. Note,
that the RBGA format contains an alpha value as well as red, green,
and blue values for each
pixel. The alpha value
is a measure of opacity, and is used for multiple image blending
and compositing. For now you can simply set the alpha byte for each pixel to
255, which means fully opaque, or you can fetch the alpha value
from the Magick++ image
canvas, as we will discuss in class.
Provide a
reshape callback routine for your program, that responds to the
user resizing the display window. If the user increases the size
of the display window so that it is bigger than the image, the
image should remain centered in the window (note that the OpenGL glViewport() command might
come in handy for this). If the user decreases the size of the
display window so that it is smaller than the image the image
should be uniformly scaled down to the largest size that will
still fit the window (note that the OpenGL command glPixelZoom() might come in
handy for this).
Please write the program in C++ , using OpenGL and GLUT graphics routines for the display. Make sure to put a comment header in each file of your code that gives a description of the program or object, your name, the date, and instructions on how it is used.