August 2000
CA208 : 'C' PROGRAMMING

QUESTION 4

Total Marks: 15 Marks

Click here to access other questions

Click to access
SUGGESTED SOLUTIONS
for Question 4

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:
typedef unsigned char 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.
void Colour2Grey(Pixel* p); [3 marks]

(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.
void Image2Grey(Pixel* img, int width, int height); [4 marks]

(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.
void FlipImage(Pixel* img[height][width]); [5 marks]