August 2000 QUESTION 4 Total Marks: 15 Marks |
Click here to access other
questions
Click to access |
Modern computer monitors are capable
of displaying over 16 million colours. Each pixel is represented using
three bytes - one byte for each of the colours red, green and blue.
Consider the following data type for a byte: (a) Define a data structure, called Pixel, which contains variables which represent each of the three colours r, g and b. [3 marks] (b) Implement a procedure, called Colour2Grey,
the signature of which is given below, which takes a reference to
a Pixel and sets the value of the pixel to grey. Conversion to grey
is achieved by assigning to each of the three colours the average
of the three colours. (c) Implement a procedure, called Image2Grey,
the signature of which is given below, which takes in a pointer to
a rectangular shaped image of width pixels wide, and height pixels
high, and converts each pixel to grey. (d) Implement a procedure, called FlipImage,
the signature of which is given below, which takes in an image represented
as a 2-dimensional array. The procedure should ip the image about
the vertical axis, such that the left+n pixel is interchanged with
the right-n pixel. |